<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="作业种类" prop="workCategory">
        <el-input
          v-model="queryParams.workCategory"
          placeholder="请输入作业种类"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="作业项目" prop="workProject">
        <el-input
          v-model="queryParams.workProject"
          placeholder="请输入作业项目"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="证书编号" prop="certificateNo">
        <el-input
          v-model="queryParams.certificateNo"
          placeholder="请输入证书编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="证书有效期起" prop="validityStartTime">
        <el-date-picker clearable
          v-model="queryParams.validityStartTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择证书有效期起">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="证书有效期止" prop="validityEndTime">
        <el-date-picker clearable
          v-model="queryParams.validityEndTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择证书有效期止">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="发证单位" prop="issuingAuthority">
        <el-input
          v-model="queryParams.issuingAuthority"
          placeholder="请输入发证单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="原发证机关" prop="originalAuthority">
        <el-input
          v-model="queryParams.originalAuthority"
          placeholder="请输入原发证机关"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="原证书编号" prop="originalCertificateNo">
        <el-input
          v-model="queryParams.originalCertificateNo"
          placeholder="请输入原证书编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="首次领证日期" prop="firstIssueDate">
        <el-date-picker clearable
          v-model="queryParams.firstIssueDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择首次领证日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="到期日期" prop="expireDate">
        <el-date-picker clearable
          v-model="queryParams.expireDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择到期日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="费用" prop="specialCertificateFee">
        <el-input
          v-model="queryParams.specialCertificateFee"
          placeholder="请输入费用"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="缴费id" prop="paymentId">
        <el-input
          v-model="queryParams.paymentId"
          placeholder="请输入缴费id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发票id" prop="invoiceId">
        <el-input
          v-model="queryParams.invoiceId"
          placeholder="请输入发票id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否上传考试系统(0:否,1:是)" prop="uploadExamSystem">
        <el-input
          v-model="queryParams.uploadExamSystem"
          placeholder="请输入是否上传考试系统(0:否,1:是)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="临近过期期限(天)" prop="expireReminderDays">
        <el-input
          v-model="queryParams.expireReminderDays"
          placeholder="请输入临近过期期限(天)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注" prop="specialCertificateRemark">
        <el-input
          v-model="queryParams.specialCertificateRemark"
          placeholder="请输入备注"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="createdTime">
        <el-date-picker clearable
          v-model="queryParams.createdTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="更新时间" prop="updatedTime">
        <el-date-picker clearable
          v-model="queryParams.updatedTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择更新时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['training:specialCertificate:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['training:specialCertificate:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['training:specialCertificate:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['training:specialCertificate:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="specialCertificateList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="特设证书id" align="center" prop="specialCertificateId" />
      <el-table-column label="证书类型" align="center" prop="certificateType" />
      <el-table-column label="证书模板id" align="center" prop="templateId" />
      <el-table-column label="学员id" align="center" prop="studentId" />
      <el-table-column label="项目id" align="center" prop="projectId" />
      <el-table-column label="报名id" align="center" prop="registrationId" />
      <el-table-column label="作业种类" align="center" prop="workCategory" />
      <el-table-column label="作业项目" align="center" prop="workProject" />
      <el-table-column label="证书编号" align="center" prop="certificateNo" />
      <el-table-column label="证书有效期起" align="center" prop="validityStartTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.validityStartTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="证书有效期止" align="center" prop="validityEndTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.validityEndTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="发证单位" align="center" prop="issuingAuthority" />
      <el-table-column label="复审状态" align="center" prop="reviewStatus" />
      <el-table-column label="原发证机关" align="center" prop="originalAuthority" />
      <el-table-column label="原证书编号" align="center" prop="originalCertificateNo" />
      <el-table-column label="首次领证日期" align="center" prop="firstIssueDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.firstIssueDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="到期日期" align="center" prop="expireDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.expireDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="费用" align="center" prop="specialCertificateFee" />
      <el-table-column label="缴费id" align="center" prop="paymentId" />
      <el-table-column label="发票id" align="center" prop="invoiceId" />
      <el-table-column label="是否上传考试系统(0:否,1:是)" align="center" prop="uploadExamSystem" />
      <el-table-column label="临近过期期限(天)" align="center" prop="expireReminderDays" />
      <el-table-column label="备注" align="center" prop="specialCertificateRemark" />
      <el-table-column label="创建时间" align="center" prop="createdTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createdTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新时间" align="center" prop="updatedTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updatedTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['training:specialCertificate:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['training:specialCertificate:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改特设证书管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="证书模板id" prop="templateId">
          <el-input v-model="form.templateId" placeholder="请输入证书模板id" />
        </el-form-item>
        <el-form-item label="学员id" prop="studentId">
          <el-input v-model="form.studentId" placeholder="请输入学员id" />
        </el-form-item>
        <el-form-item label="项目id" prop="projectId">
          <el-input v-model="form.projectId" placeholder="请输入项目id" />
        </el-form-item>
        <el-form-item label="报名id" prop="registrationId">
          <el-input v-model="form.registrationId" placeholder="请输入报名id" />
        </el-form-item>
        <el-form-item label="作业种类" prop="workCategory">
          <el-input v-model="form.workCategory" placeholder="请输入作业种类" />
        </el-form-item>
        <el-form-item label="作业项目" prop="workProject">
          <el-input v-model="form.workProject" placeholder="请输入作业项目" />
        </el-form-item>
        <el-form-item label="证书编号" prop="certificateNo">
          <el-input v-model="form.certificateNo" placeholder="请输入证书编号" />
        </el-form-item>
        <el-form-item label="证书有效期起" prop="validityStartTime">
          <el-date-picker clearable
            v-model="form.validityStartTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择证书有效期起">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="证书有效期止" prop="validityEndTime">
          <el-date-picker clearable
            v-model="form.validityEndTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择证书有效期止">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="发证单位" prop="issuingAuthority">
          <el-input v-model="form.issuingAuthority" placeholder="请输入发证单位" />
        </el-form-item>
        <el-form-item label="原发证机关" prop="originalAuthority">
          <el-input v-model="form.originalAuthority" placeholder="请输入原发证机关" />
        </el-form-item>
        <el-form-item label="原证书编号" prop="originalCertificateNo">
          <el-input v-model="form.originalCertificateNo" placeholder="请输入原证书编号" />
        </el-form-item>
        <el-form-item label="首次领证日期" prop="firstIssueDate">
          <el-date-picker clearable
            v-model="form.firstIssueDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择首次领证日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="到期日期" prop="expireDate">
          <el-date-picker clearable
            v-model="form.expireDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择到期日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="费用" prop="specialCertificateFee">
          <el-input v-model="form.specialCertificateFee" placeholder="请输入费用" />
        </el-form-item>
        <el-form-item label="缴费id" prop="paymentId">
          <el-input v-model="form.paymentId" placeholder="请输入缴费id" />
        </el-form-item>
        <el-form-item label="发票id" prop="invoiceId">
          <el-input v-model="form.invoiceId" placeholder="请输入发票id" />
        </el-form-item>
        <el-form-item label="是否上传考试系统(0:否,1:是)" prop="uploadExamSystem">
          <el-input v-model="form.uploadExamSystem" placeholder="请输入是否上传考试系统(0:否,1:是)" />
        </el-form-item>
        <el-form-item label="临近过期期限(天)" prop="expireReminderDays">
          <el-input v-model="form.expireReminderDays" placeholder="请输入临近过期期限(天)" />
        </el-form-item>
        <el-form-item label="备注" prop="specialCertificateRemark">
          <el-input v-model="form.specialCertificateRemark" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="创建时间" prop="createdTime">
          <el-date-picker clearable
            v-model="form.createdTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="更新时间" prop="updatedTime">
          <el-date-picker clearable
            v-model="form.updatedTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择更新时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listSpecialCertificate, getSpecialCertificate, delSpecialCertificate, addSpecialCertificate, updateSpecialCertificate } from "@/api/training/specialCertificate"

export default {
  name: "SpecialCertificate",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 特设证书管理表格数据
      specialCertificateList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        certificateType: null,
        workCategory: null,
        workProject: null,
        certificateNo: null,
        validityStartTime: null,
        validityEndTime: null,
        issuingAuthority: null,
        reviewStatus: null,
        originalAuthority: null,
        originalCertificateNo: null,
        firstIssueDate: null,
        expireDate: null,
        specialCertificateFee: null,
        paymentId: null,
        invoiceId: null,
        uploadExamSystem: null,
        expireReminderDays: null,
        specialCertificateRemark: null,
        createdTime: null,
        updatedTime: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询特设证书管理列表 */
    getList() {
      this.loading = true
      listSpecialCertificate(this.queryParams).then(response => {
        this.specialCertificateList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        specialCertificateId: null,
        certificateType: null,
        templateId: null,
        studentId: null,
        projectId: null,
        registrationId: null,
        workCategory: null,
        workProject: null,
        certificateNo: null,
        validityStartTime: null,
        validityEndTime: null,
        issuingAuthority: null,
        reviewStatus: null,
        originalAuthority: null,
        originalCertificateNo: null,
        firstIssueDate: null,
        expireDate: null,
        specialCertificateFee: null,
        paymentId: null,
        invoiceId: null,
        uploadExamSystem: null,
        expireReminderDays: null,
        specialCertificateRemark: null,
        createdTime: null,
        updatedTime: null,
        exampleOne: null,
        exampleTwo: null,
        exampleThree: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.specialCertificateId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加特设证书管理"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const specialCertificateId = row.specialCertificateId || this.ids
      getSpecialCertificate(specialCertificateId).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改特设证书管理"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.specialCertificateId != null) {
            updateSpecialCertificate(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addSpecialCertificate(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const specialCertificateIds = row.specialCertificateId || this.ids
      this.$modal.confirm('是否确认删除特设证书管理编号为"' + specialCertificateIds + '"的数据项？').then(function() {
        return delSpecialCertificate(specialCertificateIds)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('training/specialCertificate/export', {
        ...this.queryParams
      }, `specialCertificate_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
